package logic

import (
	"cart_srv/model/redis"
	"context"

	"cart_srv/cart"
	"cart_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type TotalCartLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewTotalCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TotalCartLogic {
	return &TotalCartLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *TotalCartLogic) TotalCart(in *cart.TotalCartRequest) (*cart.TotalCartResponse, error) {
	count, num, err := redis.TotalCart(int(in.UserId))
	if err != nil {
		logx.Error("累加失败")
		return nil, err
	}

	return &cart.TotalCartResponse{
		CheckCount: int64(count),
		CheckTotal: float32(num),
	}, nil
}
